package com.ibeeking.found.content.api.feign.fallback;

import com.ibeeking.found.content.api.feign.ContentMemberCClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import com.ibeeking.found.content.api.common.dto.MemberInfoDTO;
import java.util.List;
import java.util.Set;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class ContentMemberCFallbackFactory implements FallbackFactory<ContentMemberCClient> {
    @Override
    public ContentMemberCClient create(Throwable throwable) {
        return new ContentMemberCClient() {

            @Override
            public ResponseResult<MemberInfoDTO> infoOne(Long id) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "查询会员信息失败。" + throwable.getMessage(), null);
            }

            @Override
            public ResponseResult<MemberInfoDTO> infoOneByPhone(String phone) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "根据手机号查询会员信息失败。" + throwable.getMessage(), null);
            }

            @Override
            public ResponseResult<List<MemberInfoDTO>> infoList(Set<Long> ids) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "查询会员信息失败。" + throwable.getMessage(), Collections3.emptyList());
            }
        };
    }
}
